import { ref } from 'vue';
import { Input, message } from 'ant-design-vue';
import { useAuthStore } from '@/store/modules/auth';
import { isNonNegativeInteger } from '@/utils';

let topFormModel;
let bottomFormModel;
const lotType = ref('input');
const lotids = ref([]);
const moduleNoSearchData = ref(null);
const authStore = useAuthStore();

export default {
  url: '/qms/agv/SilkPrintingMachine/find',
  addUrl: '/qms/agv/SilkPrintingMachine/add',
  editUrl: '/qms/agv/SilkPrintingMachine/update',
  delUrl: '/qms/agv/SilkPrintingMachine/deleteBatch',
  modalGetTableDataUrl: '/qms/agv/SilkPrintingMachine/',
  editMethod: 'put',
  delMethod: 'put',
  searchFormList: [
    {
      type: 'input',
      key: 'modelVersion',
      label: '版本型号',
      placeholder: '请输入版本型号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 6
    },
    {
      type: 'input',
      key: 'lotNumber',
      label: 'LOT号',
      placeholder: '请输入LOT号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 6
    },
    {
      type: 'input',
      key: 'serialNum',
      label: '单据号',
      placeholder: '请输入单据号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 6
    },
    {
      type: 'input',
      key: 'machineNumber',
      label: '机台编号',
      placeholder: '请输入机台编号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 6
    },
    {
      type: 'select',
      key: 'state',
      label: '审核状态',
      placeholder: '请选择审核状态',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 6,
      selectOptions: [
        {
          value: '0',
          label: '待领班审核'
        },
        {
          value: '1',
          label: '待修改'
        },
        {
          value: '2',
          label: '待主管审核'
        },
        {
          value: '3',
          label: '审核完成'
        }
      ]
    },

    {
      type: 'dateRangePicker',
      key: 'time',
      label: '时间',
      span: 24,
      md: 12,
      lg: 10,
      xl: 8,
      xxl: 6
    }
  ],
  searchParam: ref({
    modelVersion: null,
    lotNumber: null,
    machineNumber: null,
    state: null,
    time: null
  }),
  column: [
    {
      key: 'dataIndex',
      dataIndex: 'dataIndex',
      title: '序号',
      width: 70,
      fixed: 'left',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'modelVersion',
      dataIndex: 'modelVersion',
      title: '型号版本',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'lotNumber',
      dataIndex: 'lotNumber',
      title: 'LOT号',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'serialNum',
      dataIndex: 'serialNum',
      title: '单据号',
      width: 130,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'state',
      dataIndex: 'state',
      title: '状态',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        return ['待领班审核', '待修改', '待主管审核', '审核完成'][record.state];
      }
    },
    {
      key: 'time',
      dataIndex: 'time',
      title: '时间',
      width: 170,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'machineNumber',
      dataIndex: 'machineNumber',
      title: '机台编号',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'copperThickness',
      dataIndex: 'copperThickness',
      title: '铜厚',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'tnumber',
      dataIndex: 'tnumber',
      title: '网版T数',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'inkModel',
      dataIndex: 'inkModel',
      title: '油墨型号',
      width: 280,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'inkNumber',
      dataIndex: 'inkNumber',
      title: '油墨批号',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'inkColor',
      dataIndex: 'inkColor',
      title: '油墨颜色',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'silkPrintNumber',
      dataIndex: 'silkPrintNumber',
      title: '丝印数量',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'plugHoles',
      dataIndex: 'plugHoles',
      title: '是否塞孔',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'inkThickness',
      dataIndex: 'inkThickness',
      title: '湿油墨厚要求',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'testInkThickness',
      dataIndex: 'testInkThickness',
      title: '生产测量墨厚',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'bladeNumber',
      dataIndex: 'bladeNumber',
      title: '刮刀编号',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'operator',
      dataIndex: 'operator',
      title: '操作员',
      width: 110,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'foreman',
      dataIndex: 'foreman',
      title: '领班审核',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'foremanTime',
      dataIndex: 'foremanTime',
      title: '领班审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examiner',
      dataIndex: 'examiner',
      title: '主管审核',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examinerTime',
      dataIndex: 'examinerTime',
      title: '主管审核时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'checkType1',
      dataIndex: 'checkType1',
      title: '首件检查',
      width: 90,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'checkType2',
      dataIndex: 'checkType2',
      title: '自主检查',
      width: 90,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'checkType3',
      dataIndex: 'checkType3',
      title: '末件检查',
      width: 90,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'shiftType',
      dataIndex: 'shiftType',
      title: '班别',
      width: 120,
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        return ['白班', '夜班'][record.shiftType];
      }
    },
    {
      key: 'remark',
      dataIndex: 'remark',
      title: '备注',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'createTime',
      dataIndex: 'createTime',
      title: '创建时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateTime',
      dataIndex: 'updateTime',
      title: '修改时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateBy',
      dataIndex: 'updateBy',
      title: '修改人',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    }
  ],

  scroll: { x: 2500, y: 'auto' },
  topFormList: [
    // 用于获取model
    {
      type: 'getModel',
      hidden: true,
      handle(topModel, personModle) {
        topFormModel = topModel;
        bottomFormModel = personModle;
      }
    },

    {
      type: 'searchInput',
      key: 'lotNumber',
      label: 'Lot号',
      span: 8,
      rule: {
        required: true,
        message: '请输入Lot号',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      disabled: false,
      transfromSearch(model, searchData) {
        topFormModel = model;
        moduleNoSearchData.value = searchData;
        Object.keys(model.value).forEach(item => {
          model.value[item] = searchData[item] || model.value[item];
        });
        topFormModel.value.time = searchData.modifyTime;
        topFormModel.value.workingPeriod = searchData.shiftType;
        topFormModel.value.lotNumber = searchData.lotId;
        topFormModel.value.modelVersion = searchData.moduleNo;
        topFormModel.value.copperThickness = searchData.copperThick;
        topFormModel.value.silkPrintNumber = searchData.quantity;
        topFormModel.value.inkColor = searchData.resistInkColor;
        topFormModel.value.tnumber = searchData.tnumber;
        topFormModel.value.inkModel = searchData.resistModel;
        if (searchData.plugHoles === '√') {
          topFormModel.value.plugHoles = '是';
        } else {
          topFormModel.value.plugHoles = '否';
        }
      }
    },

    {
      type: 'input',
      key: 'modelVersion',
      label: '型号版本',
      span: 8,
      rule: {
        required: true,
        message: '请输入型号版本',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'datePicker',
      key: 'time',
      label: '时间',
      span: 8,
      rule: {
        required: true,
        message: '请选择时间',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      showTime: true
    },
    {
      type: 'input',
      key: 'copperThickness',
      label: '铜厚',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'tnumber',
      label: '网版T数',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'inkModel',
      label: '油墨型号',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'inkNumber',
      label: '油墨批号',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'inkColor',
      label: '油墨颜色',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'silkPrintNumber',
      label: '丝印数量',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'inkThickness',
      label: '湿油墨厚要求',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'testInkThickness',
      label: '生产测量墨厚',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'bladeNumber',
      label: '刮刀编号',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'radio',
      key: 'plugHoles',
      label: '是否塞孔',
      span: 8,

      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          label: '是',
          value: '是'
        },
        {
          label: '否',
          value: '否'
        }
      ]
    },

    {
      type: 'radio',
      key: 'workingPeriod',
      label: '班别',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          label: '白班',
          value: '0'
        },
        {
          label: '夜班',
          value: '1'
        }
      ]
    },

    {
      span: 8,
      type: ''
    },
    {
      type: 'radio',
      key: 'checkType1',
      label: '首件检查',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          label: 'OK',
          value: 'OK'
        },
        {
          label: 'NG',
          value: 'NG'
        }
      ]
    },
    {
      type: 'radio',
      key: 'checkType2',
      label: '自主检查',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          label: 'OK',
          value: 'OK'
        },
        {
          label: 'NG',
          value: 'NG'
        }
      ]
    },
    {
      type: 'radio',
      key: 'checkType3',
      label: '末件检查',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          label: 'OK',
          value: 'OK'
        },
        {
          label: 'NG',
          value: 'NG'
        }
      ]
    },
    {
      type: 'input',
      key: 'checkNum1',
      label: '首件检查数量',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkNum2',
      label: '自主检查数量',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'checkNum3',
      label: '末件检查数量',
      span: 8,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'select',
      key: 'machineNumber',
      label: '机台编号',
      search: true,
      span: 6,
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          value: '机台号1',
          label: '机台号1'
        },
        {
          value: '机台号2',
          label: '机台号2'
        },
        {
          value: '机台号3',
          label: '机台号3'
        },
        {
          value: '机台号4',
          label: '机台号4'
        },
        {
          value: '机台号5',
          label: '机台号5'
        },
        {
          value: '机台号6',
          label: '机台号6'
        },
        {
          value: '机台号7',
          label: '机台号7'
        },
        {
          value: '机台号8',
          label: '机台号8'
        },
        {
          value: '机台号9',
          label: '机台号9'
        },
        {
          value: '机台号10',
          label: '机台号10'
        },
        {
          value: '机台号11',
          label: '机台号11'
        },
        {
          value: '机台号12',
          label: '机台号12'
        },
        {
          value: '机台号13',
          label: '机台号13'
        },
        {
          value: '机台号14',
          label: '机台号14'
        },
        {
          value: '机台号15',
          label: '机台号15'
        },
        {
          value: '机台号16',
          label: '机台号16'
        },
        {
          value: '机台号17',
          label: '机台号17'
        },
        {
          value: '机台号18',
          label: '机台号18'
        },
        {
          value: '机台号19',
          label: '机台号19'
        },
        {
          value: '机台号20',
          label: '机台号20'
        }
      ]
    },
    {
      type: 'textarea',
      key: 'remark',
      label: '备注',
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      textareaRows: 1,
      span: 24
    }
  ],
  bottomList: [
    {
      type: 'input',
      key: 'operator',
      label: '作业员',
      defaultValue: authStore.userInfo.user.nickName || authStore.userInfo.user.userName,
      disabled: true,
      span: 8
    },
    {
      type: 'input',
      key: 'foreman',
      label: '领班审核',
      disabled: true,
      span: 8
    },
    {
      type: 'input',
      key: 'examiner',
      label: '主管审核',
      disabled: true,
      span: 8
    }
  ],
  modalHeight: '80vh',
  modalTableKey: 'badId',
  modalAddTableKey: 'badDoList',
  modalTableColumn: [
    {
      key: 'index',
      dataIndex: 'index',
      title: '序号',
      width: 70,
      fixed: 'left',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'badName',
      dataIndex: 'badName',
      title: '检验项目',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'number',
      dataIndex: 'number',
      title: '缺陷数量',
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        if (record.disabled) {
          return <div style="min-width:150px">{record.number}</div>;
        }
        return (
          <Input
            style="height: 22px !important;"
            value={record.number}
            onBlur={e => {
              const value = e.target.value;
              if (!(isNonNegativeInteger(Number(value).toString()) && Number(value >= 0))) {
                message.error('请输入正整数');
                record.number = null;
                return;
              }
              record.number = Number(value);
            }}
          ></Input>
        );
      }
    }
  ],
  modleSearchUrlObj: {
    lotNumber: '/rcerp/agv/erp/findByLotNo'
  },
  modalGetTableUrlSuffix: {
    add: 'selectBadId',
    byId: 'listBad'
  },
  modalClose() {
    lotType.value = 'input';
    moduleNoSearchData.value = null;
    lotids.value = [];
  }
};
